package com.usian.admin.kafka;

/**
 * @author xiaowanmate
 * @date 2023/2/25 20:13
 */
import com.usian.admin.service.WemediaNewsAutoScanService;
import com.usian.common.wemedia.WemediaContans;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.util.Optional;

@Component
public class WemediaNewsAutoListener {

    @Autowired
    WemediaNewsAutoScanService wemediaNewsAutoScanService;

    @KafkaListener(topics = WemediaContans.Auto_Scan)
    public void recevieMessage(ConsumerRecord<?,?> record){
        Optional<? extends ConsumerRecord<?, ?>> optional = Optional.ofNullable(record);
        if(optional.isPresent()){
            Object value = record.value();
            wemediaNewsAutoScanService.autoScanByMediaNewsId(Long.valueOf((String) value));
        }
    }
}
